package com.enumdemo;

enum Shrubbery {
	GROUND, CRAWLING, HANGING
};

public class Demo1 {

	public static void main(String[] args) {
		// values()：返回enum实例的数组
		for (Shrubbery s : Shrubbery.values()) {
			// ordinal()返回每个enum实例在声明时的次序
			System.out.println(s + " ordinal:" + s.ordinal());

			System.out.println(s.compareTo(Shrubbery.CRAWLING) + " ");
			System.out.println(s.equals(Shrubbery.CRAWLING) + " ");
			// enum类型可以直接用==来比较
			System.out.println(s == Shrubbery.CRAWLING);
			// getDeclaringClass()所属的enum类
			System.out.println(s.getDeclaringClass());
			// name()enum声明时的名字，与toString()差不多
			System.out.println(s.name());
			System.out.println("======================");
		}

		for (String s : "HANGING CRAWLING GROUND".split(" ")) {
			// valueOf()根据给定的名字返回enum实例，如果不存在给定名字的实例，则抛出异常
			Shrubbery sh = Enum.valueOf(Shrubbery.class, s);
			System.out.println(sh);
		}
	}

}
